<template>
	<view>
		<mescroll-uni :down="downOption" @down="downCallback" :up="upOption" @up="upCallback">
			<view class="my-header">
				<image :src="my_info.status==1&&my_info.image_url?my_info.image_url:image_url"></image>
				<text v-if="my_info.status==1">￥{{my_info.amount}}</text>
				<view class="recharge" @tap="recharge">充值</view>
			</view>
			
			<tui-list-view title="充值明细" class="tui-list-view">
				<tui-list-cell class="tui-list">
					<view class="tui-list-cell-name">支付金额</view>
					<view class="tui-list-cell-name">到账金额</view>
					<view class="tui-list-cell-name">支付时间</view>
				</tui-list-cell>
				
				<tui-list-cell class="tui-list" v-for="(item,index) in recharge_log_list" :key="index">
					<view class="tui-list-cell-name">{{item.deliver_money}}</view>
					<view class="tui-list-cell-name">{{item.total_money}}</view>
					<view class="tui-right">{{item.updated_at}}</view>
				</tui-list-cell>
			</tui-list-view>
		</mescroll-uni>	
	</view>
</template>

<script>
	import tuiListView from "@/components/list-view/list-view"
	import tuiListCell from "@/components/list-cell/list-cell"
	import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue";
	import RechargeList from './recharge_list-model.js'
	var recharge_list = new RechargeList(); 
	export default {
		components: {
			tuiListView,
			tuiListCell,
			MescrollUni
		},
		data() {
			return {
				downOption: {},
				page:1,
				total:0,
				my_info:{},//用户信息
				image_url:'../../static/images/my/mine_def_touxiang_3x.png',//默认头像
				recharge_log_list:[],
				upOption:{
					page: {
						size: 20 // 每页数据的数量,默认10
					}
				}
			}
		},
		onShow(){
			this.my();
		},
		methods: {
			my(){
				var that = this;
				recharge_list.my((res)=>{
					if(res.code==8888){
						that.my_info = res.data;
					}
				})
			},
			recharge(){
				recharge_list.navigate_to('../recharge/recharge');
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				try{
					var that = this;
					that.page = 1;
				} catch (e) {
					mescroll.endErr();
				}
				mescroll.resetUpScroll();
			},
			/*上拉加载的回调: mescroll携带page的参数, 其中num:当前页 从1开始, size:每页数据条数,默认10 */
			upCallback(mescroll) {
					var that = this;
					that.get_recharge_log_list((res)=>{
						mescroll.endBySize(res.data.length, res.total);
					})
			},
			//获取充值记录列表
			get_recharge_log_list(callback){
				var that = this;
				recharge_list.get_recharge_log_list(that.page,(res)=>{
					if(res.code == 8888){
						if(res.data.current_page == 1){
							that.recharge_log_list = res.data.data;
							that.total = res.data.total;
						}else{
							for(var i=0;i<res.data.data.length;i++){
								that.recharge_log_list.push(res.data.data[i]);
							}
						}
					}
					if(callback){
						if(that.page < res.data.last_page){
							that.page = that.page + 1;
						}
						callback(res.data);
					}
				});
			}
		}
		
	}
</script>

<style>
	@import url("recharge_list.css");
</style>
